import QtQuick 2.12


// 带文字的SwitchButton
Rectangle{

    id: root

    // public ========================================================

    height: 40*dp
    width: Math.max(text_0.contentWidth, text_1.contentWidth) * 2 + 60*dp       // 默认宽度根据文字尺寸自动调节

    property string text0: "内容0"
    property string text1: "内容1"

    property int checked: 0         // 当前选中的编号
    property string text: checked===0 ? text0 : text1       // 当前选中的文字内容


    // 颜色
    property color borderColor: config.themeColor           // 边框颜色
    property color backgroundColor_checked: "white"         // 选中背景颜色
    property color textColor_checked: config.themeColor     // 选中文字颜色
    property color backgroundColor: config.themeColor       // 背景颜色
    property color textColor: "white"                       // 文字颜色
    radius: 4*dp

    // private ========================================================

    border.color: borderColor
    CustomRectangle{
        id: rect_0
        radius_lb: root.radius-1
        radius_lt: root.radius-1
        height: root.height - 2
        width: root.width * 0.5 - 1
        x: 1; y: 1
        color: checked === 0 ? backgroundColor_checked : backgroundColor
        Text{
            id: text_0
            text: text0
            anchors.centerIn: parent
            color: checked === 0 ? textColor_checked : textColor
            font.pixelSize: config.fontsize
        }

        MouseArea{
            anchors.fill: parent
            cursorShape: Qt.PointingHandCursor
            onClicked: {
                checked = 0
            }
        }
    }
    CustomRectangle{
        id: rect_1
        radius_rb: root.radius-1
        radius_rt: root.radius-1
        x: root.width * 0.5; y: 1
        height: root.height - 2
        width: root.width * 0.5 - 1
        color: checked === 1 ? backgroundColor_checked : backgroundColor
        Text{
            id: text_1
            text: text1
            anchors.centerIn: parent
            color: checked === 1 ? textColor_checked : textColor
            font.pixelSize: config.fontsize
        }

        MouseArea{
            anchors.fill: parent
            cursorShape: Qt.PointingHandCursor
            onClicked: {
                checked = 1
            }
        }
    }

    Rectangle{

    }


}
